# GNAFU - "Ground, Navy and Air Fuck-Up" real-time strategy game
# Copyright (C) 2008-2009 k0wax <k0waxk0wax@gmail.com>
#
# This file is part of GNAFU.
#
# GNAFU is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GNAFU is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNAFU.  If not, see <http://www.gnu.org/licenses/>.

from __future__ import division, absolute_import
import pyglet
#from src import inp
from src.vars import vars
from src.consts import *

class GameWindow(pyglet.window.Window):
    def on_draw(self):
        self.clear()
    def on_mouse_motion(self, x, y, dx, dy):
        from src import inp
        inp.m.x, inp.m.y = x, y
    def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
        from src import inp
        print x, y, dx, dy
        print inp.m.cx, inp.m.cy
        inp.m.x, inp.m.y = x, y
    def on_mouse_press(self, x, y, buttons, modifiers):
        print 'PRESSED', x, y
    def on_mouse_release(self, x, y, buttons, modifiers):
        from src import inp
        inp.m.x, inp.m.y = x, y
    def on_key_press(self, sym, mod):
        from src import inp
        sym_str_lc = pyglet.window.key.symbol_string(sym).lower()
        print sym_str_lc, 'Pressed'
        inp.kb.handle_key(sym_str_lc)
        return pyglet.event.EVENT_HANDLED
    def save_screenshot(self, fn=None): # XXX move
        import time
        if fn is None:
            fn = 'misc/shots/s10_%s.png' % time.strftime('%Y%m%d%H%M%S', time.localtime())
        pyglet.image.get_buffer_manager().get_color_buffer().save(fn)
        print 'Screenshot saved to %s' % fn

def init_once(f):
    def wrapper(*args, **kw):
        print '=> src.win [init]'
        rv = f(*args, **kw)
        print '=> src.win [done]'
        return rv
    return wrapper

